package com.hitqz.robot.biz.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hitqz.robot.api.common.entity.PatrolCheckType;
import com.hitqz.robot.api.common.entity.PatrolObject;
import com.hitqz.robot.api.common.entity.PatrolObjectStandard;
import com.hitqz.robot.biz.mapper.PatrolCheckTypeMapper;
import com.hitqz.robot.biz.mapper.PatrolObjectMapper;
import com.hitqz.robot.biz.service.PatrolCheckTypeService;
import com.hitqz.robot.biz.service.PatrolObjectService;
import com.hitqz.robot.biz.service.PatrolObjectStandardService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wengyx
 * @date 2024/8/7
 */
@Service
@AllArgsConstructor
public class PatrolObjectServiceIml extends ServiceImpl<PatrolObjectMapper, PatrolObject> implements PatrolObjectService {

    final private PatrolObjectStandardService patrolObjectStandardService;

    @Override
    public void removeSelfAndStandardBatchByCheckTypeIds(Integer[] ids) {
        if (ids.length==0){
            return;
        }
        //查询出底下所有的巡检对象
        List<PatrolObject> patrolObjects = baseMapper.selectList(Wrappers.<PatrolObject>lambdaQuery().in(PatrolObject::getPatrolCheckTypeId, ids));
        if (CollUtil.isEmpty(patrolObjects)){
            return;
        }
        //删除底下所有的巡检对象
        baseMapper.delete(Wrappers.<PatrolObject>lambdaQuery().in(PatrolObject::getId, CollUtil.getFieldValues(patrolObjects, "id")));
        //删除底下所有的标准值
        patrolObjectStandardService.remove(Wrappers.<PatrolObjectStandard>lambdaQuery().in(PatrolObjectStandard::getPatrolObjectId, ids));
    }
}
